<%@page import="java.util.Date"%>
<%@page import="com.iflysse.bbs.model.NewsInfo"%>
<%@page import="com.iflysse.bbs.dao.impl.NewsDaoImpl"%>
<%@page import="com.iflysse.bbs.dao.NewsDao"%>
<%@page import="com.iflysse.bbs.model.UserInfo"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="../base.jsp"%>
<%
	//检查是否登陆
	if (session.getAttribute("currentUser") == null) {
		request.getRequestDispatcher("/index_handler.jsp").forward(
				request, response);
		return;
	}

	String newsid = request.getParameter("newsid") == null ? null
			: request.getParameter("newsid").toString().trim();
	String title = request.getParameter("title") == null ? null
			: request.getParameter("title").toString().trim();
	String content = request.getParameter("content") == null ? null
			: request.getParameter("content").toString().trim();

	UserInfo currentUser = (UserInfo) session
			.getAttribute("currentUser");

	NewsInfo newsInfo = new NewsInfo();
	newsInfo.setTitle(title);
	newsInfo.setContent(content);
	newsInfo.setDate(new Date(System.currentTimeMillis()));
	newsInfo.setUserId(currentUser.getId());

	NewsDao newsDao = new NewsDaoImpl();
	boolean flag = false;
	if (newsid == null) {
		newsDao.add(newsInfo);
	} else {
		newsInfo.setId(Integer.valueOf(newsid).intValue());
		newsDao.edit(newsInfo);
	}

	response.sendRedirect("newslist_handler.jsp");
%>